const config = require('../common/config');
const commonReq = require('./commonReq');

function setMyShareCode(shareCode) {
    wx.setStorage({
        key: config.storage.keyShareCode,
        data: shareCode
    })
}

function setMyShareDesc(desc) {
    wx.setStorage({
        key: config.storage.keyShareDesc,
        data: desc
    })
}

function getMyShareCode() {
    return wx.getStorageSync(config.storage.keyShareCode);
}

function getMyShareDesc() {
    return wx.getStorageSync(config.storage.keyShareDesc);
}

function getFriendShareCode() {
    let pages = getCurrentPages(),
        currentPage = pages[pages.length - 1],
        options = currentPage.options,
        shareCode = options.shareCode;
    return shareCode || ''
}

function getShareDetail(path = 'houseList') {
    let shareCode = getMyShareCode();
    let shareDesc = getMyShareDesc();
    let businessSource = 1003;

    console.log(shareCode);
    return {
        title: shareDesc,
        path: `/pages/${path}/${path}?shareCode=${shareCode}`,
        success: function (res){
            console.log('common share util success');
            commonReq.makePoint(businessSource)
        }
    }
}

module.exports = {
    setMyShareCode,
    getMyShareCode,
    setMyShareDesc,
    getMyShareDesc,
    getShareDetail,
    getFriendShareCode
};